Batch methods


In [1]:
# standard imports
import matplotlib.pyplot as plt
import pandas as pd
import os
import tempfile
%matplotlib inline
# import seaborn as sbn # can be used for getting nice colormaps and good settings of the matplotlib rc

In [2]:
# some tweaks to change the apperance of the notebook (you dont have to use these if you dont like them)

# big figures
from IPython.core.pylabtools import figsize
figsize(14, 7)

# full width
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))



In [3]:
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
    return false;
}



In [ ]:
# cellpy imports
from cellpy.utils import batch

In [ ]:
def clean_dir():
    new_path = tempfile.mkdtemp()
    return new_path

In [ ]:
def batch_instance(clean_dir):
    prms = batch.prms
    prms.Paths["db_filename"] = test_db_filename
    prms.Paths["cellpydatadir"] = test_data_dir_cellpy
    prms.Paths["outdatadir"] = clean_dir
    prms.Paths["rawdatadir"] = test_data_dir_raw
    prms.Paths["db_path"] = test_data_dir_db
    prms.Paths["filelogdir"] = clean_dir
    return batch.init(log_level="DEBUG")

In [ ]:
# -------- defining overall path-names etc ----------
current_file_path = os.getcwd()
relative_test_data_dir = "../testdata"
test_data_dir = os.path.abspath(os.path.join(current_file_path, relative_test_data_dir))

test_data_dir_raw = os.path.join(test_data_dir, "data")
test_data_dir_out = os.path.join(test_data_dir, "out")
test_data_dir_cellpy = os.path.join(test_data_dir, "hdf5")
test_data_dir_db = os.path.join(test_data_dir, "db")

test_cellpy_file = "20160805_test001_45_cc.h5"
test_cellpy_file_full = os.path.join(test_data_dir_cellpy,test_cellpy_file)

test_cellpy_file_tmp = "tmpfile.h5"
test_cellpy_file_tmp_full = os.path.join(test_data_dir_cellpy,test_cellpy_file_tmp)

test_db_filename = "cellpy_db.xlsx"
test_db_filename_full = os.path.join(test_data_dir_db,test_db_filename)

test_run_name = "20160805_test001_45_cc"

test_res_file = "20160805_test001_45_cc_01.res"
test_res_file_full = os.path.join(test_data_dir_raw,test_res_file)

In [ ]:
out_dir = clean_dir()
print(out_dir)

In [ ]:
b = batch_instance(out_dir)

In [ ]:
# Name of the experimental set (as defined in the excel-file)
name = "test"
project = "ProjectOfRun"
b.name = name
b.project = project

In [ ]:
# some options for loading, exporting and saving
b.export_raw = True
b.export_cycles = True
b.export_ica = False
b.save_cellpy_file = True
b.force_raw_file = True
b.force_cellpy_file = False
b.shifted_cycles = True

# adding some extra things to make a summary of:
b.selected_summaries.extend(["shifted_charge_capacity", "shifted_discharge_capacity", "low_level", "high_level",])

In [ ]:
b.create_journal()

In [ ]:
b.create_folder_structure()

In [ ]:
b.update()

In [ ]:
b.make_summaries()

In [ ]:
p = os.path.join(out_dir, b.project)
print(p)
p = os.path.join(p, b.name)
os.listdir(p)
r = os.path.join(p, 'raw_data')
os.listdir(r)

In [ ]:
f = os.path.join(r, '20160805_test001_47_cc_01_cycles.csv')
cycles = pd.read_csv(f, sep=';')

In [ ]:
cycles.head()

In [ ]:
cycles.tail()

In [ ]:
fig, ax = plt.subplots(1,1)
ax.plot(cycles["cap cycle_no 1"], cycles["voltage cycle_no 1"], label="cycle 1")
ax.plot(cycles["cap cycle_no 2"], cycles["voltage cycle_no 2"], label="cycle 2")
ax.plot(cycles["cap cycle_no 3"], cycles["voltage cycle_no 3"], label="cycle 3")
plt.legend()

In [ ]:
import shutil

In [ ]:
shutil.rmtree(p)

In [ ]: